# -*- coding: utf-8 -*-
# @Time    : 2021/8/30 15:05
# @Author  : BrandonGT

import sys
from PyQt5.QtWidgets import *

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("测试")
        self.resize(500, 500)
        self.adjustSize()
        self.setup_ui()

    def mousePressEvent(self, evt):
        local_x = evt.x()
        local_y = evt.y()
        sub_widget = self.childAt(local_x, local_y)
        if sub_widget != None:
            print(1)
            sub_widget.setStyleSheet("background-color: red")

    def setup_ui(self):
        for i in range(1, 11):
            label = QLabel(self)
            label.setText("标题 %s" % i)
            label.adjustSize()
            label.move(50*i, 50*i)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())